package TP1;

import java.io.File;
import java.util.Vector;

public class Indexeur {
	IndexInterface index;

	/*public Indexeur(IndexInterface index) {
		this.index = index;
	}

	public void parcourDir(Vector<String> dirNameList) {
		for (String dir : dirNameList) {
			addDirtoIndex(dir);
		}
		index.MakeIndex();
	}*/

	/*public void parcourDir(String dirName) {
		addDirtoIndex(dirName);
		index.MakeIndex();
	}

	private void addDirtoIndex(String dirName) {
		File dossierPrincipal = new File(dirName);
		if (dossierPrincipal.isDirectory()) {
			for (String fileName : dossierPrincipal.list()) {
				File fichier = new File(dirName + File.separator + fileName);
				if (fichier.isFile()) {
					index.addDocToIndex(fichier);
				}
			}
		}
	}

	public void parcourDirEvalue(Vector<String> dirNameList, StatsIndex stats) {
		int BonneReponse = 0, MauvaiseReponse = 0;
		int erreurS = 0, erreurH = 0;
		int spam = 0, ham = 0;
		float result;

		for (String dirName : dirNameList) {
			File dossierPrincipal = new File(dirName);
			if (dossierPrincipal.isDirectory()) {
				for (String fileName : dossierPrincipal.list()) {
					File fichier = new File(dirName + File.separator + fileName);
					if (fichier.isFile()) {
						result = index.evalueDocument(fichier);
						if (fileName.startsWith("spm")) {
							spam++;
							if (result < 0) {
								erreurS++;
								MauvaiseReponse++;
							} else {
								BonneReponse++;
							}
						} else {
							ham++;
							if (result > 0) {
								erreurH++;
								MauvaiseReponse++;
							} else {
								BonneReponse++;
							}
						}
					}
				}
			}
		}
		int nbReponse = BonneReponse + MauvaiseReponse;
		int pBonneReponse = (int) ((BonneReponse / (float) nbReponse) * 10000);
		System.out.println("" + nbReponse + " r�ponses : "
				+ (pBonneReponse / 100.f) + "%bonne " + MauvaiseReponse
				+ "mauvaise r�ponses");
		int pSpam = (int) ((erreurS / (float) spam) * 10000);
		System.out.println("" + spam + " spam : " + (pSpam / 100.f)
				+ "%erreurSpam " + erreurS + "erreur spam");
		int pHam = (int) ((erreurH / (float) ham) * 10000);
		System.out.println("" + ham + " ham : " + (pHam / 100.f)
				+ "%erreurHam " + erreurH + "erreur Ham");
		// System.out.println("bonne reponse : " + BonneReponse +
		// ", mauvaise r�ponse : " + MauvaiseReponse);
		stats.add(nbReponse, pBonneReponse, MauvaiseReponse, spam, pSpam,
				erreurS, ham, pHam, erreurH);
	}

	public void parcourDirEvalue(String dirName, StatsIndex stats) {
		Vector<String> toEvalue = new Vector<String>();
		toEvalue.add(dirName);
		parcourDirEvalue(toEvalue, stats);
	}*/
}
